package com.ytwl.controller.truck;

import com.ytwl.bean.RespBean;
import com.ytwl.bean.RespPageBean;
import com.ytwl.bean.TruckTeam;
import com.ytwl.service.TruckTeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/truck/team")
public class TruckTeamController {
    @Autowired
    TruckTeamService truckTeamService;

    @PutMapping("/")
    public RespBean updateTruckTeamById(@RequestBody TruckTeam truckTeam) {
        if (truckTeamService.updateTruckTeamById(truckTeam) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteTruckTeamById(@PathVariable Integer id) {
        if (truckTeamService.deleteTruckTeamById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @PostMapping("/")
    public RespBean addTruckTeam(@RequestBody TruckTeam truckTeam) {
        if (truckTeamService.addTruckTeam(truckTeam) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @GetMapping("/")
    public RespPageBean getAllTruckTeamByPage(Integer page, Integer size, String keyword) {
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(truckTeamService.getAllTruckTeamByPage(page,size,keyword));
        respPageBean.setTotal(truckTeamService.getTotal(keyword));
        return respPageBean;
    }
}
